package dome4;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

public class Test {
    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("hello",1);
        map.put("abcd",8);
        map.put("world",4);
        map.put("feifei",2);

        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.print("key: " + s);
                System.out.println("  val: " + integer);
            }
        });

        System.out.println("=====");

        map.forEach((key,val) -> System.out.println("key: " + key + " val: " + val));
    }
    public static void main1(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("abcd");
        list.add("world");
        list.add("feifei");
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        System.out.println("=======");

        list.forEach(s -> System.out.println(s));

        System.out.println("====排序====");

//        list.sort(new Comparator<String>() {
//            @Override
//            public int compare(String o1, String o2) {
//                return o1.compareTo(o2);
//            }
//        });
//        System.out.println("========");
        list.sort((o1,o2) -> o1.compareTo(o2));
        list.forEach(s -> System.out.println(s));
    }
}
